const Joi = require('joi');

const createSection = Joi.object({
  name: Joi.string().trim().min(1).max(200).required(),
  description: Joi.string().trim().max(1000).allow(''),
  order: Joi.number().min(1).optional(),
  forms: Joi.array().items(
    Joi.alternatives().try(
      Joi.string().hex().length(24),
      Joi.object().unknown(true)
    )
  ).optional(), // 添加forms字段验证
  config: Joi.object({
    showInToc: Joi.boolean(),
    pageBreak: Joi.boolean(),
    titleAlign: Joi.string().valid('left', 'center'),
    numbering: Joi.object({
      enabled: Joi.boolean(),
      format: Joi.string().trim()
    })
  }).optional()
});

const updateSection = createSection.fork(['name'], (schema) => schema.optional());

const reorderSections = Joi.object({
  sections: Joi.array().items(
    Joi.object({
      id: Joi.string().hex().length(24).required(),
      order: Joi.number().min(1).required()
    })
  ).required()
});

module.exports = {
  createSection,
  updateSection,
  reorderSections
};